<template>
  <el-container>
    <el-header>
      <div class="header-content">
        <h1>工作流审批系统</h1>
        <div class="user-info" v-if="user">
          <span>{{ user.username }}</span>
          <el-button type="text" @click="logout">退出</el-button>
        </div>
      </div>
    </el-header>
    
    <el-container>
      <el-aside width="200px">
        <el-menu
          router
          :default-active="$route.path"
          class="el-menu-vertical"
        >
          <el-menu-item index="/">
            <el-icon><HomeFilled /></el-icon>
            <span>首页</span>
          </el-menu-item>
          
          <el-menu-item index="/workflows">
            <el-icon><List /></el-icon>
            <span>我的流程</span>
          </el-menu-item>
          
          <el-menu-item index="/tasks">
            <el-icon><Check /></el-icon>
            <span>待办事项</span>
          </el-menu-item>
          
          <el-divider v-if="user && ['admin', 'manager'].includes(user.role)" />
          
          <el-menu-item index="/workflow-templates" v-if="user && ['admin', 'manager'].includes(user.role)">
            <el-icon><Document /></el-icon>
            <span>流程模板管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { HomeFilled, List, Check, Document } from '@element-plus/icons-vue'
import axios from 'axios'

const router = useRouter()
const user = ref(null)

onMounted(async () => {
  try {
    const response = await axios.get('/auth/profile')
    user.value = response.data
  } catch (error) {
    router.push('/login')
  }
})

const logout = () => {
  localStorage.removeItem('token')
  router.push('/login')
}
</script>

<style scoped>
.el-header {
  background-color: #409EFF;
  color: white;
  line-height: 60px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.el-aside {
  background-color: #f5f7fa;
}

.el-menu-vertical {
  height: 100%;
}

.el-main {
  padding: 20px;
}
</style> 